package com.mybatis.demo.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mybatis.demo.mapper.DeptMapper;
import com.mybatis.demo.pojo.dto.SaveDeptDto;
import com.mybatis.demo.pojo.dto.UpdateDeptDto;
import com.mybatis.demo.pojo.dto.getPageDeptDto;
import com.mybatis.demo.pojo.po.BaseWorker;
import com.mybatis.demo.service.DeptService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *@ClassName DeptServiceImpl
 *@Author 郭承乐
 *@Date 2024/8/21 13:58
 *@Version 1.0
 **/
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public void saveDept(SaveDeptDto dto) {
        BaseWorker baseWorker = BeanUtil.copyProperties(dto, BaseWorker.class);
        deptMapper.saveDept(baseWorker);
    }

    @Override
    public List<BaseWorker> listDept() {
        return deptMapper.listDept();
    }

    @Override
    public void deleteDept(Integer id) {
        deptMapper.deleteDept(id);
    }

    @Override
    public void updateDept(UpdateDeptDto dto) {
        BaseWorker baseWorker = BeanUtil.copyProperties(dto, BaseWorker.class);
        deptMapper.updateDept(baseWorker);
    }

    @Override
    public List<BaseWorker> getPageDept(getPageDeptDto dto) {
        //开启分页，设置分页参数
        PageHelper.startPage(dto.getPageNo(),dto.getPageSize());
        Page<BaseWorker> pageList = deptMapper.getPageDept(dto);
        return pageList.getResult();
    }
}
